package com.springboot.cloud.demos.producer.dao;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.springboot.cloud.demos.entity.po.Order;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
@Mapper
public interface OrderMapper extends BaseMapper<Order> {
    @Select("SELECT o.id,o.user_id as userId, o.level_id as levelId,o.status,o.consignee," +
            "o.mobile as consigneeMobile,CONCAT(o.province,o.city,o.district,o.address)as address,o.pay_money as payMoney ,o.balance," +
            "u.nickname,u.mobile ,l.title as levelName ,l.cover,l.subtitle,o.created_time as createdTime" +
            " FROM t_order o" +
            " LEFT JOIN t_user u ON u.id= o.user_id" +
            " LEFT JOIN t_level l ON l.id= o.level_id ")
    IPage<Map<String, Object>> selectMapsPage(IPage page, @Param("ew") Wrapper queryWrapper);


    @Select("SELECT o.id,o.user_id as userId, o.level_id as levelId,o.status,o.consignee," +
            "o.mobile as consigneeMobile,o.province,o.city,o.district,o.address,o.pay_money as payMoney ,o.balance," +
            "u.nickname,u.mobile ,l.title as levelName ,l.cover,l.subtitle,o.created_time as createdTime" +
            " FROM t_order o" +
            " LEFT JOIN t_user u ON u.id= o.user_id" +
            " LEFT JOIN t_level l ON l.id= o.level_id where o.user_id=#{userId} and deleted='N' order by o.created_time desc")
    List<Map<String, Object>> query(@Param("userId") String userId);
}
